package com.dtagri.fjwlw.fragment;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.widget.ListView;

import com.dtagri.fjwlw.AppContext;
import com.dtagri.fjwlw.R;
import com.dtagri.fjwlw.adapter.RealTimeDataAdapter;
import com.dtagri.fjwlw.api.FJwlwApi;
import com.dtagri.fjwlw.base.BaseSimpleFragment;
import com.dtagri.fjwlw.base.TGson;
import com.dtagri.fjwlw.bean.TjAreaMsg;
import com.dtagri.fjwlw.bean.TjCompanyRegion;
import com.google.gson.reflect.TypeToken;

/**
 * 实时数据
 * 
 * @author wxjn
 * 
 */
public class RealTimeDataFragment extends BaseSimpleFragment {
	protected ListView listView;

	protected List<TjAreaMsg> tjAreaMsgs = new ArrayList<TjAreaMsg>();

	private RealTimeDataAdapter realTimeDataAdapter;

	@Override
	protected void xOnSuccess(byte[] arg2) {
		Type type = new TypeToken<List<TjAreaMsg>>() {
		}.getType();
		tjAreaMsgs = TGson.gson.fromJson(new String(arg2), type);
		realTimeDataAdapter = new RealTimeDataAdapter(getActivity(), tjAreaMsgs);
		listView.setAdapter(realTimeDataAdapter);
	}

	@Override
	public void initView(View view) {
		super.initView(view);
		listView = (ListView) view.findViewById(R.id.listview);
		// new Timer().schedule(new TimerTask() {
		//
		// @Override
		// public void run() {
		// TjCompanyRegion tjCompanyRegion = AppContext.user
		// .getTjCompanyRegions().get(
		// AppContext.userOperate.getCurBaseIndex());
		// FJwlwApi.realTimeData(tjCompanyRegion.getRegionId(), mHandler);
		// }
		// }, 1000, 1000);
	}

	@Override
	protected void xInitData() {
		TjCompanyRegion tjCompanyRegion = AppContext.user.getTjCompanyRegions()
				.get(AppContext.userOperate.getCurBaseIndex());
		FJwlwApi.realTimeData(tjCompanyRegion.getRegionId(), mHandler);
	}

	@Override
	protected int getLayoutId() {
		return R.layout.layout_simple_list;
	}

	@Override
	protected String getCacheKey() {
		return null;
	}
}
